<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="box">
        <div class="box">
            <div class="top">
                <span class="title">电影排行</span>
                <ul class="tabs">
                    <li :class="{active : active}" v-on:mouseover="toggleAction('hit')">热播</li>
                    <li :class="{active : active}" v-on:mouseover="toggleAction('classic')">经典</li>
                </ul>
            </div>
            <component :is="current" :hitmovie="hitmovie" :classicmovie="classicmovie"></component>
        </div>
    </div>
    <script>
        var vm = new Vue({
            el: "#box",
            data:{
                active: true,
                current: "hit",
                hitmovie: [ //热播电影数组
                    { name : "终结者5", star : "大手"},
                    { name : "终结者2", star : "大手"},
                    { name : "终结者4", star : "大手"},
                    { name : "终结者7", star : "大手"},
                    { name : "终结者5", star : "大手"},
                    { name : "终结者9", star : "大手"},
                    { name : "终结者5", star : "大手"},
                ],
                classicmovie: [
                    {name : "西游记", star: "🐂马"},
                    {name : "西游记", star: "🐂马"},
                    {name : "西游记", star: "🐂马"},
                    {name : "西游记", star: "🐂马"},
                    {name : "西游记", star: "🐂马"},
                    {name : "西游记", star: "🐂马"},
                    {name : "西游记", star: "🐂马"},
                ]
            },
            methods: {
                toggleAction : function(value){
                    this.current = value;
                    value == "hit" ? this.active = true : this.active = false;
                }
            },
            // 注册局部组件
            components: {
                hit: {
                    props: ['hitmovie'], //传递prop
                    template: `<div class="main">
                        <div v-for="(item,index) in hitmovie">
                            <span>{{++index}}</span>
                            <span>{{item.name}}</span>
                            <span>{{item.star}}</span>
                        </div></div>`
                },
                classic: {
                    props : ['classicmovie'], //传递prop
                    template : `<div class="main">
                        <div v-for="(item,index) in classicmovie">
                            <span>{{++index}}</span>
                            <span>{{item.name}}</span>
                            <span>{{item.star}}</span>
                        </div></div>`
                }
            }
        })

    </script>
    
</body>
</html>